package com.lichuandi.future;

import java.util.concurrent.*;

public class FutureExample {
    public static void main(String[] args) throws Exception {
        ExecutorService executor = Executors.newFixedThreadPool(2);
        Future<String> future = executor.submit(() -> {
            Thread.sleep(1000);
            return "Hello from Future!";
        });

        System.out.println("主线程做其他事情...");
        String result = future.get(); // 阻塞直到结果就绪
        System.out.println(result);
        executor.shutdown();
    }
}